﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using Serm;
using System.Data.OleDb;

namespace TestForm
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Serm.ReportMaker.MakeReport("ExcelTemplate1.xlsx", "Out1.xlsx", GetDataFromAccess("PrintData.accdb"));
            Process.Start("Out1.xlsx");
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Serm.ReportMaker.MakeReport("ExcelTemplate2.xlsx", "Out2.xlsx", "PrintData.csv");
            Process.Start("Out2.xlsx");
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Serm.ReportMaker.MakeReport("ExcelTemplate3.xlsx", "Out3.xlsx", GetDataFromAccess("PrintData.accdb"));
            Process.Start("Out3.xlsx");
        }

        private DataTable GetDataFromAccess(string FileName)
        {
            OleDbConnection cn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + FileName);
            DataTable dt = new DataTable();
            OleDbDataAdapter da = new OleDbDataAdapter();
            OleDbCommand cmd = new OleDbCommand("SELECT * FROM Table1;", cn);
            cn.Open();
            using (da.SelectCommand = cmd)
            {
                da.Fill(dt);
            }
            cn.Close();
            return dt;
        }

    }
}
